<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/26
 * Time: 10:43
 */

namespace app\financial\model;


use think\Model;

class HelpAwardModel extends Model
{

    public function getList($filter)
    {
        $where=['t.delete_time'=>0];

        if(isset($filter['status'])  && !empty($filter['status']))
        {
            $where['c.status']=$filter['status'];
        }
        if(!empty($filter['code']))
        {
            $where['t.code|t.old_code']=$filter['code'];
        }
        if(!empty($filter['name']))
        {
            $where['t.name']=$filter['name'];
        }
        if(!empty($filter['tname']))
        {
            $where['t.name']=['like',"%".trim($filter['tname'])."%"];
        }
        $homework_starttime = empty($filter['create_time']) ? 0 : strtotime($filter['create_time']);
        $homework_endtime   = empty($filter['create_time1']) ? 0 : strtotime($filter['create_time1']);
        if (!empty($homework_starttime) && !empty($homework_endtime)) {
            $where['c.create_time'] = [['>= time', $homework_starttime], ['<= time', $homework_endtime]];
        } else {
            if (!empty($homework_starttime)) {
                $where['c.create_time'] = ['>= time', $homework_starttime];
            }
            if (!empty($homework_endtime)) {
                $where['c.create_time'] = ['<= time', $homework_endtime];
            }
        }
        $field='c.*,t.name tname,t.code,at.filename,at.file_path,u.user_login uname ';
        $data=$this->alias('c')->field($field)
            ->join('student t','t.id=c.student_id')
            ->join('asset at','at.id=c.asset_id')
            ->join('user u','u.id=c.u_id',$type='left')
            ->where($where)
            ->order('c.id','DESC')
            ->paginate(10,false,['query' => $filter]);
        return $data;

    }

}